/*
 * @lc app=leetcode.cn id=3 lang=csharp
 *
 * [3] 无重复字符的最长子串
 */

// @lc code=start
public class Solution {
    public int LengthOfLongestSubstring(string s) {
        var dict = new Dictionary<char, int>();
        var left = 0;
        var max = 0;
        for(int i = 0; i < s.Length; i++)
        {
            if(dict.ContainsKey(s[i]))
            {
                left = Math.Max(left, dict[s[i]] + 1);
            }
            dict[s[i]] = i;
            max = Math.Max(max, i - left + 1);
        }
        return max;
    }
}
// @lc code=end

